cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(recipe-10 LANGUAGES CXX)

# Windows 下导出所有符号（可选）
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

# ---- 1. 动态库 ----
add_library(animals SHARED
  src/animal.hpp
  src/animal.cpp
  src/cat.hpp
  src/cat.cpp
  src/dog.hpp
  src/dog.cpp
  src/factory.hpp
)

# 强制使用 C++14，关闭扩展，开启 PIC
set_target_properties(animals PROPERTIES
  CXX_STANDARD            14
  CXX_STANDARD_REQUIRED   ON
  CXX_EXTENSIONS          OFF
  POSITION_INDEPENDENT_CODE ON
)

# ---- 2. 可执行程序 ----
add_executable(animal-farm
  app/main.cpp
)

# 同样的 C++14 设置
set_target_properties(animal-farm PROPERTIES
  CXX_STANDARD            14
  CXX_STANDARD_REQUIRED   ON
  CXX_EXTENSIONS          OFF
)

# 链接 animals 库
target_link_libraries(animal-farm PRIVATE animals)